const { contextBridge, ipcRenderer } = require('electron');
// 出于安全原因，请勿将 event 参数暴露给渲染器！

contextBridge.exposeInMainWorld('ipcRenderer', {
    on: (channel, listener) => {
        ipcRenderer.on(channel, (event, ...args) => listener(...args))
    },
    off: (channel, listener) => {
        ipcRenderer.off(channel, (event, ...args) => listener(...args))
    },
    once: (channel, listener) => {
        ipcRenderer.once(channel, (event, ...args) => listener(...args))
    },
    addListener: (channel, listener) => {
        ipcRenderer.addListener(channel, (event, ...args) => listener(...args))
    },
    removeListener: (channel, listener) => {
        ipcRenderer.removeListener(channel, (event, ...args) => listener(...args))
    },
    removeAllListener: (channel) => {
        ipcRenderer.removeAllListeners(channel)
    },
    send: (channel, ...args) => {
        ipcRenderer.send(channel, ...args);
    },
    invoke: (channel, ...args) => {
        return ipcRenderer.invoke(channel, ...args);
    },
    sendSync: (channel, ...args) => {
        return ipcRenderer.sendSync(channel, ...args);
    },
    postMessage: (channel, message, transfer) => {
        ipcRenderer.postMessage(channel, message, transfer);
    },
    sendToHost: (channel, ...args) => {
        ipcRenderer.sendToHost(channel, ...args);
    },
});

contextBridge.exposeInMainWorld('process', {
    NODE_ENV: process.env.NODE_ENV
})